package queueDemo;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class Demo4 {
    public static void main(String[] args) {
        BlockingQueue<Integer> queue4 = new ArrayBlockingQueue<Integer>(1);
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 2; i++) {
                System.out.println(queue4.offer(1));
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 3; i++) {
                try {
                    Thread.sleep(1000);
                    System.out.println(queue4.poll());
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        t1.start();
        t2.start();
    }
}
